const bcrypt = require('bcryptjs')
const { query } = require('../config/database')

async function addTestUser () {
  try {
    // 清空现有用户数据（谨慎操作）
    console.log('清空现有用户数据...')
    await query('DELETE FROM users')

    // 创建测试用户
    const hashedPassword = await bcrypt.hash('123456', 10)

    await query(
      'INSERT INTO users (email, username, password_hash, nickname, is_vip, coin_balance) VALUES (?, ?, ?, ?, ?, ?)',
      ['admin@example.com', 'admin', hashedPassword, '管理员', true, 9999]
    )

    await query(
      'INSERT INTO users (email, username, password_hash, nickname, is_vip, coin_balance) VALUES (?, ?, ?, ?, ?, ?)',
      ['user@example.com', 'user', hashedPassword, '普通用户', false, 100]
    )

    console.log('✅ 测试用户创建成功！')
    console.log('登录信息：')
    console.log('  admin@example.com / 123456 (管理员)')
    console.log('  user@example.com / 123456 (普通用户)')
  } catch (error) {
    console.error('❌ 创建测试用户失败:', error)
  }

  process.exit(0)
}

addTestUser()
